
//useRef 对元素或者组件进行引用
import React ,{useRef} from 'react'
    const UseRefHook = ()=>{
        //组件ref引用
        let inputRef = useRef()
        let comRef = useRef()
     const handleClick=()=>{
            console.log(inputRef);
            inputRef.current.focus()
            console.log(comRef);
        }

        return(
            <fieldset>
                <legend>UseRefHook</legend>
            <input type="text" name="" id="" ref = {inputRef} />
            <button onClick = {handleClick} >点击获取焦点</button>
            <Child ref= {comRef}></Child>
            </fieldset>
        )
    }

    class Child extends React.Component {
        render(){
            return(
                <fieldset>
                    <legend>Child</legend>
                    <h1>子组件</h1>
                </fieldset>
            )
        }
    }
    export default UseRefHook